home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / Completions / Demo Application / FileCopier.h < prev    next >
Encoding:
Text File  |  1998-06-19  |  2.7 KB  |  116 lines  |  [TEXT/CWIE]

  1. // FileCopier.h
  2.  
  3. #ifndef FileCopier_h
  4. #define FileCopier_h
  5.  
  6. #ifndef FileCreator_h
  7. #include "FileCreator.h"
  8. #endif
  9. #ifndef FileOutStream_h
  10. #include "FileOutStream.h"
  11. #endif
  12. #ifndef FileOpener_h
  13. #include "FileOpener.h"
  14. #endif
  15. #ifndef FileInStream_h
  16. #include "FileInStream.h"
  17. #endif
  18. #ifndef FileCloser_h
  19. #include "FileCloser.h"
  20. #endif
  21. #ifndef BufferOfSize_h
  22. #include "BufferOfSize.h"
  23. #endif
  24. #ifndef ConstBufferMaster_h
  25. #include "ConstBufferMaster.h"
  26. #endif
  27. #ifndef TaskSequencer_h
  28. #include "TaskSequencer.h"
  29. #endif
  30. #ifndef TaskStep_h
  31. #include "TaskStep.h"
  32. #endif
  33. #ifndef Race_h
  34. #include "Race.h"
  35. #endif
  36. #ifndef InputPump_h
  37. #include "InputPump.h"
  38. #endif
  39. #ifndef OutputPump_h
  40. #include "OutputPump.h"
  41. #endif
  42. #ifndef Pipe_h
  43. #include "Pipe.h"
  44. #endif
  45. #ifndef FileWritingPath_h
  46. #include "FileWritingPath.h"
  47. #endif
  48. #ifndef CatInfoChanger_h
  49. #include "CatInfoChanger.h"
  50. #endif
  51.  
  52. /*
  53.     This is an off-the-cuff file copying Task, which may serve as an example.
  54.     In some ways it's an example of poor practice: it checks no errors,
  55.     doesn't die when dying is set, and doesn't use PBAllocate.  Also,
  56.     it floods the File Manager so much that other processes can hardly
  57.     get a call in edgewise.
  58. */
  59.  
  60. class FileCopier
  61.   {
  62.     private:
  63.         const FSSpec *sourceFile;
  64.         const FSSpec *destinationFile;
  65.         uint32 dataCopied;
  66.         
  67.         FileReadingPath sourcePath;
  68.         FileWritingPath destinationPath;
  69.         
  70.         FileCreator create;
  71.         FileOpener open;
  72.         FileCloser close;
  73.         FileInStream inStream;
  74.         FileOutStream outStream;
  75.         CatInfoChanger info;
  76.         
  77.         InputPump pumpIn;
  78.         OutputPump pumpOut;
  79.         Race2 race;
  80.         
  81.         uint8 buffer[1024 * 1024 + 4096];
  82.         Pipe pipe;
  83.         
  84.         TaskSequencer<FileCopier> sequence;
  85.         typedef TaskStep<FileCopier> Step;
  86.         
  87.         Step CreateDestination( bool dying, DeferredTaskTime );
  88.  
  89.         Step GetSourceInfo( bool dying, DeferredTaskTime );
  90.         Step SetDestinationInfo( bool dying, DeferredTaskTime );
  91.  
  92.         Step OpenDestinationData( bool dying, DeferredTaskTime );
  93.         Step OpenSourceData( bool dying, DeferredTaskTime );
  94.         Step CopyData( bool dying, DeferredTaskTime );
  95.         Step CloseSourceData( bool dying, DeferredTaskTime );
  96.         Step CloseDestinationData( bool dying, DeferredTaskTime );
  97.  
  98.         Step OpenDestinationResources( bool dying, DeferredTaskTime );
  99.         Step OpenSourceResources( bool dying, DeferredTaskTime );
  100.         Step CopyResources( bool dying, DeferredTaskTime );
  101.         Step CloseSourceResources( bool dying, DeferredTaskTime );
  102.         Step CloseDestinationResources( bool dying, DeferredTaskTime );
  103.         
  104.     public:
  105.         FileCopier();
  106.         
  107.         Task *operator()( const FSSpec& source,
  108.                                 const FSSpec& destination );
  109.                                 
  110.         uint32 Position() const            { return outStream.Position() + dataCopied; }
  111.         uint32 MaxPosition() const        { return info.hFileInfo.ioFlLgLen
  112.                                                             + info.hFileInfo.ioFlRLgLen; }
  113.   };
  114.  
  115. #endif
  116.